package com.yc.thread;

import java.util.concurrent.atomic.AtomicInteger;

public class TestJoin {
	
	public void test1() {
		Thread t1 = new Thread(() -> {
			for (int i = 0; i < 10; i++) {
				System.out.println("------------t1");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		});
		
		Thread t2 = new Thread(() -> {
			for (int i = 0; i < 3; i++) {
				System.out.println("------------t2");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		});
		t2.start();
		t1.start();
		try {
			t1.join();
			t2.join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("-----main-----");
		
		
	}
	
	public void testJoin2(){
		Thread t1 = new Thread(() -> {
			System.out.println("---------t1--start");
			
			Thread t2 = new Thread(() -> {
				for (int j = 0; j < 10; j++) {
					System.out.println("------------t2");
				}
				System.out.println("---------t2--end");
			});
			t2.start();
			
//			try {
//				t2.join();
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}
			
			for (int i = 0; i < 10; i++) {
				System.out.println("------------t1");
				
			}
			System.out.println("---------t1--end");
		});
		
		System.out.println(t1.getState().toString());
		
		
		t1.start();
	}
	
	public void ma() {
		
	}
	

	public static void main(String[] args) {
		TestJoin tj = new TestJoin();
//		tj.test1();
		tj.testJoin2();

	}

}

